package cn.xuchunh.campusbbs.base;

import android.content.res.TypedArray;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.facebook.rebound.Spring;
import com.facebook.rebound.SpringSystem;
import com.tumblr.backboard.performer.Performer;

import java.util.ArrayList;
import java.util.List;

import cn.xuchunh.campusbbs.R;
import cn.xuchunh.campusbbs.widget.ReboundShow;

/**
 * Created by XuChunH on 2015/9/11.
 */
public class TestFragment extends BaseFragment {

    @Override
    protected void initView(View view) {
        final View rect = view.findViewById(R.id.rect);
        final Spring spring = SpringSystem.create().createSpring();
        spring.addListener(new Performer(rect, View.SCALE_X));
        spring.addListener(new Performer(rect, View.SCALE_Y));
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        spring.setVelocity(0);

                    case MotionEvent.ACTION_MOVE:

                        // can't use Imitation here because there is no nice mapping from
                        // an event property to a Spring
                        float scaleX, scaleY;

                        float delta = event.getX() - (rect.getX() + rect.getMeasuredWidth() / 2);
                        scaleX = Math.abs(delta) / (rect.getMeasuredWidth() / 2);

                        delta = event.getY() - (rect.getY() + rect.getMeasuredHeight() / 2);
                        scaleY = Math.abs(delta) / (rect.getMeasuredHeight() / 2);

                        float scale = Math.max(scaleX, scaleY);

                        spring.setEndValue(scale);

                        break;
                    case MotionEvent.ACTION_UP:
                        spring.setEndValue(1f);

                        break;
                }

                return true;
            }
        });
    }

    @Override
    protected void beforeInitView() {
        setContentViewRes(R.layout.fragment_test);
    }
}
